package com.jsbb.controller;

import com.jsbb.core.Const;
import com.jsbb.util.RequestUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * IndexController
 *
 * @author jsbb
 */
@Controller
public class IndexController {

    @GetMapping(value = {"/{var1}/{var2}/index", "/{var1}/index", "/"})
    public String index(HttpServletRequest request, @PathVariable(value = "var1", required = false) String var1, @PathVariable(value = "var2", required = false) String var2) {
        String token = RequestUtils.getCookie(request, Const.COOKIE_NAME);
        if (token == null) {
            return "login";
        }
        if (var1 == null) {
            return "index";
        }
        if (var2 == null) {
            return var1;
        }
        return var1 + "/" + var2;
    }
}
